var go = setInterval("loop()",500);
function loop() {
    oDiv.addEventListener("click", add);
}

function setAlpha(iTarget){ //iTarget目标高度通过参数传入
    clearInterval(timer); //执行计时器之前，先清除计时器，否则执行完一次再执行，上次的计时器还在，会不停抖动
    timer=setInterval(function(){
        var iSpeed;
        if(height<iTarget)
        {
            iSpeed=5;
        }
        else
        {
            iSpeed=-5;
        }
        if(height == iTarget)
        {
            clearInterval(timer);
        }
        else
        {
            height+=iSpeed;
            dDiv.style.height = height + 'px';

        }
    },20);
};

function add() {

    if(dDiv.offsetHeight>0)
        setAlpha(0);
    else setAlpha(300);
}
